import prompt from '@system.prompt';
import router from '@system.router';
import { jsCallJavaAbility } from '../../common/JsCallJavaAbilityUtils.js';

export default {
    data: {
        title: "",
        localtionX:"",
        localtionY:"",
        test:"",
        test1:"",
        click:"",
        media:"",
        port:"",
        upAnimation:"",
        downAnimation:"",
        leftAnimation:"",
        rightAnimation:"",
        textAnimation:"",
        model:"手动赛",
        controlDta:"",
        armStatus:"",
        textSet:"",
        textCopy:""
    },
    onInit() {
        this.title = this.$t('strings.world');
        this.test="Welcome to Harmony Control System";
        this.media="false";
    },
    onShow(){
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '-0px 20px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.upAnimation = this.$element('upName').animate(frames, options);
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '-0px -20px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.downAnimation = this.$element('downName').animate(frames, options);
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '20px -0px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.leftAnimation = this.$element('leftName').animate(frames, options);
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '-20px -0px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.rightAnimation = this.$element('rightName').animate(frames, options);
        var options = {
            duration: 1500,
            easing:'ease-in',
            delay:5,
            fill: 'forwards',
            direction:'alternate',
            iterations:1,
        };
        // @ts-ignore
        var frames = [
            {
                transform: {
                    translate: '50px -0px'
                },
                opacity: 0.1,
                offset: 0.0,
                width: 200,
                height: 200,
            },
            {
                transform: {
                    translate: '110px 0px'
                },
                opacity: 1.0,
                offset: 1.0,
                width: 300,
                height: 300,
            }
        ];
        // this.textAnimation = this.$element('textAnimate').animate(frames, options);
    },
    upClick:async function(){
        console.log("upclick");
        this.model="Manual";
        this.test="前进";
        this.controlDta="1";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            //this.showToast(result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.upAnimation.play();
    },
    upClick2:async function(){
        console.log("upclick");
        this.model="Manual";
        this.test="加速前进";
        this.controlDta="11";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            //this.showToast(result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.upAnimation.play();
    },
    leftClick:async function(){
        console.log("leftclick")
        this.model="Manual";
        this.test="左转";
        this.controlDta="3";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.leftAnimation.play();

    },
    leftClick2:async function(){
        console.log("leftclick")
        this.model="Manual";
        this.test="加速左转";
        this.controlDta="31";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.leftAnimation.play();

    },
    rightClick:async function(){
        console.log("rightclick")
        this.model="Manual";
        this.test="右转";
        this.controlDta="4";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.rightAnimation.play();
    },
    rightClick2:async function(){
        console.log("rightclick")
        this.model="Manual";
        this.test="加速右转";
        this.controlDta="41";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.rightAnimation.play();
    },
    downClick:async function(){
        console.log("downclick")
        this.model="Manual";
        this.test="后退";
        this.controlDta="2";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.downAnimation.play();
    },
    downClick2:async function(){
        console.log("downclick")
        this.model="Manual";
        this.test="加速后退";
        this.controlDta="21";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.downAnimation.play();
    },
    stopClick:async function() {
        this.test = "";
        // this.model="停止行动";
        this.controlDta="K";
        try {
            var action = this.initAction2(1002, this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("stop");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="停止运动\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    stopClick2:async function() {
        this.test = "";
        // this.model="复位按钮";
        this.controlDta="1001";
        try {
            var action = this.initAction2(1002, this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("recover");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="复位按钮\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.textAnimation.pause();
    },
    stopClick3:async function() {
        this.test = "";
        // this.model="复位按钮";
        this.controlDta="la"
        try {
            var action = this.initAction2(1002, this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("left");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="小角度左转\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.textAnimation.pause();
    },
    stopClick4:async function() {
        this.test = "";
        // this.model="复位按钮";
        this.controlDta="ra";
        try {
            var action = this.initAction2(1002, this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("right");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="小角度右转\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.textAnimation.pause();
    },
    pickClick11:async function(){
        console.log("pick")
        this.controlDta="p11";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="11抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick12:async function(){
        console.log("pick")
        this.controlDta="p12";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="12抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick13:async function(){
        console.log("pick")
        this.controlDta="p13";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="13抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick21:async function(){
        console.log("pick")
        this.controlDta="p21";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="21抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick22:async function(){
        console.log("pick")
        this.controlDta="p22";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="22抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick31:async function(){
        console.log("pick")
        this.controlDta="p31";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="31抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick32:async function(){
        console.log("pick")
        this.controlDta="p32";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("pick up");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="32抓取\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick66:async function(){
        console.log("pick")
        this.controlDta="fa";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("move")
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="小幅度前进\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    armUp:async function(){
        this.controlDta="up";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("arm_up");
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    armDw:async function(){
        this.controlDta="dw";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("arm_down");
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickClick77:async function(){
        console.log("pick")
        this.controlDta="ba";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("move")
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="小幅度后退\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    putDownClick:async function(){
        console.log("putDown")
        this.controlDta="6";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("put down");
            if(this.test="Welcome to Harmony Control System"){
                this.test="";
            }
            this.test1="放下\n ";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    touchEnd:async function(){
        this.controlDta="#";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("stop");
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    initConnectAction:function(code,ip,port){
        var actionData={};
        actionData.ip=ip;
        actionData.port=port;
        var action={};
        action.bundleName="com.example.tcpConnect";
        action.abilityName="tcpConnectTest";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
    initAction: function (code) {
        var actionData = {};
        var action = {};
        action.bundleName="com.example.tcpConnect";
        action.abilityName="tcpConnectTest";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
    initAction2: function (code,test) {
        var actionData = {};
        actionData.test = test;
        var action = {};
        action.bundleName="com.example.tcpConnect";
        action.abilityName="tcpConnectTest";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
   printData(msg){
        if(this.outcont != null || this.outcont != ""){
            this.outcont = msg + "\n" + this.outcont;
        } else {
            this.outcont = msg;
        }
    },
    showToast:function(msg){
        prompt.showToast({
            message:msg
        })
    }
}
